//-----------------------------------------------------------------------
//<copyright file="ChiTietBienBanNhapHangDAO.cs
//Code generate by tools.
//</copyright>
//-----------------------------------------------------------------------

using System;
using System.Data;
using System.Data.Common;
using System.Collections.Generic;
using PMS.Exceptions;
using System.Data.SqlClient;
using PMS.Entity;

namespace PMS.DAL
{
	public class ChiTietBienBanNhapHangDAO : SQLDatabase, IChiTietBienBanNhapHangDAO
	{

        #region Create ChiTietBienBanNhapHang methods

        public ChiTietBienBanNhapHang CreateChiTietBienBanNhapHang(ChiTietBienBanNhapHang chiTietBienBanNhapHang)
        {
            try
            {

                SqlCommand command = SQLDatabase.StoredProcedureCommand("spChiTietBienBanNhapHangInsert");
                AddInParameter(command, "@MaBBNH", SqlDbType.NVarChar, chiTietBienBanNhapHang.MaBBNH);
                AddInParameter(command, "@MaCTPN",SqlDbType.NVarChar, chiTietBienBanNhapHang.MaCTPN);
                AddInParameter(command, "@ThucTe", SqlDbType.Int, chiTietBienBanNhapHang.ThucTe);
                AddInParameter(command, "@Thua", SqlDbType.Int, chiTietBienBanNhapHang.Thua);
                AddInParameter(command, "@Thieu", SqlDbType.Int, chiTietBienBanNhapHang.Thieu);
                AddInParameter(command, "@Hong", SqlDbType.Int, chiTietBienBanNhapHang.Hong);
                AddInParameter(command, "@TinhTrang",SqlDbType.NVarChar, chiTietBienBanNhapHang.TinhTrang);
                AddInParameter(command, "@GhiChu",SqlDbType.NVarChar, chiTietBienBanNhapHang.GhiChu);

                ExecuteNonQuery(command);
                return chiTietBienBanNhapHang;
            }
            catch (Exception ex)
            {
                throw DataAccessException.GetException("Data Access CreateChiTietBienBanNhapHangException", ex);
            }
        }

        #endregion

        #region Update ChiTietBienBanNhapHang methods

        public void UpdateChiTietBienBanNhapHang(ChiTietBienBanNhapHang chiTietBienBanNhapHang)
        {
            try
            {
                SqlCommand command = SQLDatabase.StoredProcedureCommand("spChiTietBienBanNhapHangUpdate");

                AddInParameter(command, "@MaBBNH",SqlDbType.NVarChar, chiTietBienBanNhapHang.MaBBNH);
                AddInParameter(command, "@MaCTPN",SqlDbType.NVarChar, chiTietBienBanNhapHang.MaCTPN);
                AddInParameter(command, "@ThucTe", SqlDbType.Int, chiTietBienBanNhapHang.ThucTe);
                AddInParameter(command, "@Thua", SqlDbType.Int, chiTietBienBanNhapHang.Thua);
                AddInParameter(command, "@Thieu", SqlDbType.Int, chiTietBienBanNhapHang.Thieu);
                AddInParameter(command, "@Hong", SqlDbType.Int, chiTietBienBanNhapHang.Hong);
                AddInParameter(command, "@TinhTrang",SqlDbType.NVarChar, chiTietBienBanNhapHang.TinhTrang);
                AddInParameter(command, "@GhiChu",SqlDbType.NVarChar, chiTietBienBanNhapHang.GhiChu);

                ExecuteNonQuery(command);
            }
            catch (Exception ex)
            {
                throw DataAccessException.GetException("Data Access UpdateChiTietBienBanNhapHangException", ex);
            }
        }

        #endregion

		#region Delete ChiTietBienBanNhapHang methods

		public void DeleteChiTietBienBanNhapHang(ChiTietBienBanNhapHang chiTietBienBanNhapHang)
		{
			try
			{
				SqlCommand command = SQLDatabase.StoredProcedureCommand("spChiTietBienBanNhapHangDelete");

				AddInParameter(command, "@MaBBNH", SqlDbType.NVarChar, chiTietBienBanNhapHang.MaBBNH);
                AddInParameter(command, "@MaCTPN", SqlDbType.NVarChar, chiTietBienBanNhapHang.MaCTPN);

				ExecuteNonQuery(command);
			}
			catch (Exception ex)
			{
				throw DataAccessException.GetException("Data Access DeleteChiTietBienBanNhapHangException", ex);
			}
		}

        public void DeleteChiTietBienBanNhapHangByMaBBNH(string maBBNH)
        {
            try
            {
                SqlCommand command = SQLDatabase.StoredProcedureCommand("spChiTietBienBanNhapHangDeleteAllByMaBBNH");

                AddInParameter(command, "@MaBBNH", SqlDbType.NVarChar, maBBNH);

                ExecuteNonQuery(command);
            }
            catch (Exception ex)
            {
                throw DataAccessException.GetException("Data Access DeleteChiTietBienBanNhapHangException", ex);
            }
        }

		#endregion

		#region Select methods

		#region GetAll ChiTietBienBanNhapHang methods

		public ChiTietBienBanNhapHangs GetAllChiTietBienBanNhapHang()
		{
			try
			{

				SqlCommand command = SQLDatabase.StoredProcedureCommand("spChiTietBienBanNhapHangGetList");
				ChiTietBienBanNhapHangs Result = new ChiTietBienBanNhapHangs();
				List<ChiTietBienBanNhapHang> List = ExecuteQuery<ChiTietBienBanNhapHang>(command,true);
				foreach(ChiTietBienBanNhapHang item in List)
				{
					Result.Add(item);
				}
				return Result;
			}
			catch (Exception ex)
			{
				throw DataAccessException.GetException("Data Access GetAllChiTietBienBanNhapHangException", ex);
			}
		}

        public ChiTietBienBanNhapHangs GetAllChiTietBienBanNhapHangByMaBBNH(string maBBNH)
        {
            try
            {

                SqlCommand command = SQLDatabase.StoredProcedureCommand("spChiTietBienBanNhapHangSelectAllByMaBBNH");
                AddInParameter(command, "@MaBBNH", SqlDbType.NVarChar, maBBNH);
                ChiTietBienBanNhapHangs Result = new ChiTietBienBanNhapHangs();
                List<ChiTietBienBanNhapHang> List = ExecuteQuery<ChiTietBienBanNhapHang>(command, true);
                foreach (ChiTietBienBanNhapHang item in List)
                {
                    Result.Add(item);
                }
                return Result;
            }
            catch (Exception ex)
            {
                throw DataAccessException.GetException("Data Access GetAllChiTietBienBanNhapHangException", ex);
            }
        }

		#endregion


		#region GetChiTietBienBanNhapHang methods

		public ChiTietBienBanNhapHang GetChiTietBienBanNhapHangByID(string maBBNH)
		{
			try
			{
				SqlCommand command = SQLDatabase.StoredProcedureCommand("spChiTietBienBanNhapHangGet");

				AddInParameter(command, "@maBBNH", SqlDbType.NVarChar, maBBNH);

				return ExecuteQuery<ChiTietBienBanNhapHang>(command);
			}
			catch (Exception ex)
			{
				throw DataAccessException.GetException("Data Access GetChiTietBienBanNhapHangBy ID Exception", ex);
			}
		}

		#endregion


		#endregion
	}
}//End Class
